home *** CD-ROM | disk | FTP | other *** search
- page 55,132
- ;------------------------------------------------------------------------------
- ;PASSWORD.ASM (creates PWORD.SYS, device driver)
- ;
- ;DOS 2.00 Device driver forces user to enter password on booting up
- ;and disables Ctrl-Break.
- ;
- ;After assembly: link PASSWORD (ignore "no STACK" error)
- ; exec2bin PASSWORD PASSWORD.SYS
- ; place DEVICE=PASSWORD.SYS in CONFIG.SYS file
- ; reboot system with Ctrl-Alt-Del
- ; answer prompt with: PassWord <enter>
-
- dev_seg segment
- pword_device proc far
- assume cs:dev_seg,ds:dev_seg,es:dev_seg
-
- ;-------------------------------
- ;The following lines are the device header, which must exist for
- ;every device. This file has only one device, and it works with
- ;character I/O. It doesn't actually handle any I/O services,
- ;but it's easier to create a character device.
-
- pword_dev_header: ;label for the start of the device driver
-
- next_dev_ptr dd -1 ;only 1 device is defined in this file
- dev_attribute dw 8000h ;character device (simpler that way)
- strategy_ptr dw strategy ;the installation proc
- interrupt_ptr dw interrupt ;the proc that handles all service requests
- device_name db 'PASSWORD' ;8-byte string of device name
-
- ;--- This is the stroage area for the password --
- ;--- The first byte is the length (0-16) --------
- ;--- The following characters are the password --
- ;--- Only an exact match will allow the system --
- ;--- to continue the boot process ---------------
-
- password_store db 8,'PassWord'
- db $-password_store dup(' ') ;leave room for a
- ;16 character password
-
- in_buf_max db 16 ;input buffer for reading password from user
- in_buf_len db ? ;it is set up for DOS service OAH, BUFFERED_INPUT
- in_buf db 16 dup(?)
-
- ;----- The STRATEGY proc stores ES:BX request header pointer here
- ;----- The INTERRUPT proc retrieves it
-
- request_ptr label dword ;defined as double word for LES opcode
- req_ptr_off dw ? ;and as two words for MOV opcodes
- req_ptr_seg dw ?
-
-
-
- dummy_iret: ;Ctrl-Break vector is pointed here, so it
- iret ;does nothing. Break is not recognized.
-
-
-
- ;------------------messages----------------------------------------------------
- ;These messages are expected to be output via the ANSI.SYS device,
- ;so it should be installed (named in the CONFIG.SYS file) before
- ;this PWORD device.
- ;If you don't want to use ANSI.SYS, remove the ESC sequences in the messages.
-
- lf equ 0ah
- cr equ 0dh
- esc equ 1bh
-
- msg_1 db cr,lf,esc,'[0m' ;make output visible
- db 'Enter Password: '
- db esc,'[8m$' ;make input invisible
-
- msg_2 db cr,lf,esc,'0m' ;make output visible
- db 'Password accepted.',cr,lf,'$'
-
-
-
- ;==============================================================================
- ;STRATEGY procedure
- ;Just saves the request header pointer for the INTERRUPT proc
-
- strategy proc far
- assume cs:dev_seg
-
- mov cs:req_ptr_off,bx
- mov cs:req_ptr_seg,es
- ret ;far return to DOS
- strategy endp
-
-
-
- ;==============================================================================
- ;INTERRUPT procedure
- ;Processes the command indicated in the request header.
-
- interrupt proc far
- assume cs:dev_seg,ds:nothing, es:nothing
- push ds ;preserve all registers
- push es
- push ax
- push bx
- push cx
- push dx
- push di
- push si
- mov ax,cs ;make DS address the
- mov ds,ax ;program data area
-
- les bx,request_ptr ;get the pointer saved by
- mov al,es:[bx+2] ;fetch the command
- cmp al,0
- je init_fn ;only valid request in INI
- error_exit:
- or word ptr es:[bx+3],8003H ;indicate error cod
- ;"Unknown command"
-
- ;---- interrupt service request has been handled.
- ;---- Set he "done flag" and return to DOS.
-
- common_exit:
- or word ptr es:[bx+3],100H ;set the done bit
- pop si
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- pop es
- pop ds
- ret ;far return
-
-
- ;---- Only the INIT function is handled by the PWORD device
- ;---- all other requests are routed through the error_exit.
-
- ;----------------------------------
- ;INIT_FN procedure
- ;prompts the user for a password, keeps prompting until correct entry
- ;received, Passes the address of this proc back to DOS as the end-of-driver
- ;address so that a minimum amount of storage is used.
-
- init_fn proc near
-
- push es
-
- ;--------------
- ;The following 4 lines eliminate Ctrl-Break from having
- ;any effect on the system, unless another program
- ;KEYBOARD_BREAK vector is altered (BASIC does that).
-
- mov ax,0
- mov es,ax
- mov word ptr es:[1Bh*4],offset dummy_iret
- mov word ptr es:[1Bh*4+2],cs
- jmp short no_beep
- try_again:
- mov al,7 ;bel character
- mov ah,0EH ;WRITE_TTY service
- int 10h
- no_beep:
- mov dx,offset msg_1 ;"Enter Password:"
- mov ah,9 ;DOS print string service
- int 21H
-
- mov dx,offset in_buf_max
- mov ah,0Ch ;clear input buffer and..
- mov al,0Ah ;input a line of character
- int 21H
- mov ax,cs
- mov es,ax ;set ES to target password
- ;DS already points to user
- mov si,offset in_buf_len
- mov ch,0
- mov cl,[si]
- cmp cl,[di] ;are lengths the same?
- jne try_again
- inc di ;point to first characters
- inc si ;of both strings
- rep cmpsb ;all chars the same?
- jne try_again ;no, start over
-
- mov dx,offset msg_2 ;"Password accepted"
- mov ah,9
- int 21H
-
- ;---- now exit from INIT procedure -----------------------------
- ;---- retain only the minimum amount of code -------------------
- ;---- to handle erroneous service requests ---------------------
-
- pop es
- mov word ptr es:[bx+0EH],offset init_fn
- mov word ptr es:[bx+10H],cs
-
-
- jmp common_exit
- init_fn endp
-
- interrupt endp
- pword_device endp
- dev_seg ends
- end pword_dev_header ;must specify end for EXE2